// packageAPI/pages/wxml/fields/fields.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    schema:[
      {
        label:'是否返回节点id',
        prop:'id',
        type:'switch',
      },
      {
        label:'是否返回节点dataset',
        prop:'dataset',
        type:'switch',
      },
      {
        label:'是否返回节点mark',
        prop:'mark',
        type:'switch',
      },
      {
        label:'是否返回节点布局位置',
        prop:'rect',
        type:'switch',
      },
      {
        label:'是否返回节点尺寸',
        prop:'size',
        type:'switch',
      },
      {
        label:'否 是否返回节点的 scrollLeft scrollTop，节点必须是 scroll-view 或者 viewport',
        prop:'scrollOffset',
        type:'switch',
      },
      {
        label:'指定属性名列表，返回节点对应属性名的当前属性值（只能获得组件文档中标注的常规属性值，id class style 和事件绑定的属性值不可获取）',
        prop:'properties',
        type:'text',
        placeholder: '多个值用英文逗号隔开'
      },
      {
        label:'指定样式名列表，返回节点对应样式名的当前值',
        prop:'computedStyle',
        type:'text',
        placeholder: '多个值用英文逗号隔开'
      },
      {
        label:'是否返回节点对应的 Context 对象',
        prop:'context',
        type:'switch',
      },
      {
        label:'是否返回节点对应的 Node 实例',
        prop:'node',
        type:'switch',
      },
      {
        label:'是否返回节点对应的 Ref 对象，仅 Skyline 下支持',
        prop:'ref',
        type:'switch',
      },
    ],
    formData:{
      id: false,
      dataset: false,
      mark: false,
      rect: false,
      size: false,
      scrollOffset: false,
      properties: '',
      computedStyle: '',
      context: false,
      node: false,
      ref: false
    },
    title: '',
    result: '',
    remark: '',
    webUrl: '',
    apiName: ''
  },
  onLoad(options) {
    console.log('options', options)
    wx.setNavigationBarTitle({
      title: options.title,
    })

    this.setData({
      title: options.title,
      zh:options.zh,
      remark: options.remark,
      webUrl: options.webUrl
    })
  },
  getFormData(e) {
    console.log('getFormData', e);
    this.setData({
      formData: e.detail.formData
    })
  },
  choose1() {
    console.log({
      ...this.data.formData,
      properties: (this.data.formData.properties || '').split(',').filter(i=>i),
      computedStyle: (this.data.formData.computedStyle || '').split(',').filter(i=>i)
    });
    wx.createSelectorQuery().select('#the-id').fields({
      ...this.data.formData,
      properties: (this.data.formData.properties || '').split(',').filter(i=>i),
      computedStyle: (this.data.formData.computedStyle || '').split(',').filter(i=>i)
    }, (res) => {
      wx.showModal({
        title: '执行了fields方法的回调',
        showCancel: false
      })
    }).exec((res) => {
      this.setData({
        result: res,
        apiName: 'NodesRef.fields'
      })
    })
  },
  choose2() {
    wx.createSelectorQuery().select('#the-id2').fields({
      ...this.data.formData,
      properties: (this.data.formData.properties || '').split(',').filter(i=>i),
      computedStyle: (this.data.formData.computedStyle || '').split(',').filter(i=>i)
    }, (res) => {
      wx.showModal({
        title: '执行了fields方法的回调',
        showCancel: false
      })
    }).exec((res) => {
      this.setData({
        result: res,
        apiName: 'NodesRef.fields'
      })
    })
  },
})